package com.yyjj.zixun.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.aries.ui.view.title.TitleBarView;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.yyjj.zixun.R;
import com.yyjj.zixun.api.Api;
import com.yyjj.zixun.entity.GanTouEntity;
import com.yyjj.zixun.entity.GuiJingShuDetailsEntity;
import com.yyjj.zixun.entity.ZiXunDetailsEntity;
import com.zzhoujay.richtext.RichText;

import tech.com.commoncore.base.BaseTitleActivity;
import tech.com.commoncore.constant.ApiConstant;
import tech.com.commoncore.entity.BaseTResp;

public class GanTouDetailsActivity extends BaseTitleActivity {
    private TextView tvTitle;
    private TextView tvTime;
    private TextView tvAuthor;
    private TextView tvContent;

    String id = "";

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText("详情").setBackground(getResources().getDrawable(R.drawable.btn_jb));
    }

    @Override
    public int getContentLayout() {
        return R.layout.zixun_activity_zi_xun_details;
    }

    @Override
    public void initView(Bundle savedInstanceState) {

        id = (String) getIntent().getSerializableExtra("id");


        tvTitle = (TextView) findViewById(R.id.tv_title);
        tvTime = (TextView) findViewById(R.id.tv_time);
        tvAuthor = (TextView) findViewById(R.id.tv_author);
        tvContent = (TextView) findViewById(R.id.tv_content);
        tvAuthor.setVisibility(View.GONE);
        if (id != null && id != "") {
            getDatas(id);
        }


    }

    private void getDatas(String id) {
        ViseHttp.GET(Api.NEWS_GOLD_DETAIL)
                .baseUrl(ApiConstant.BASE_URL)
                .addParam("url", id)
                .request(new ACallback<BaseTResp<GuiJingShuDetailsEntity>>() {

                    @Override
                    public void onSuccess(BaseTResp<GuiJingShuDetailsEntity> data) {
                        if ((1 == data.code) && (data.data != null)) {
                            tvTitle.setText(data.data.getTitle());
                            tvTime.setText(data.data.getDate());
                            RichText.initCacheDir(mContext);
                            RichText.fromHtml(data.data.getContent()).clickable(false).into(tvContent);

                        }
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                    }
                });

    }
}
